using System;
using System.Collections.Generic;
using System.Text;
using IGlobalist.Cms.DataAccess;
using IGlobalist.Cms.Model;

namespace IGlobalist.Cms.Bll
{
    public class OrderLineController : BaseController
    {

        public static long InsertOrderLine(IOrderLine orderLine)
        {
            long id = _Ds.InsertObject((ICmsObject)orderLine);
            if (orderLine.ParentID > 0)
            {
                //_Ds.InsertObjectRelation(orderLine.ParentID, id, (short)CmsObjectType.Order);
            }
            return id;
        }

        public static OrderLineList GetOrderLineListLelateToObjectID(long objectID)
        {
            return ConvertListObject2OrderLineList(_Ds.GetObjectListRelateToObjectID(objectID, (short)CmsObjectType.OrderLine));
        }

        private static OrderLineList ConvertListObject2OrderLineList(IList<ICmsObject> list)
        {
            OrderLineList orderLines = new OrderLineList();
            if (list != null)
                foreach (ICmsObject orderLine in list)
                {
                    orderLines.Add(ConvertCmsObject2OrderLine(orderLine));
                }
            return orderLines;
        }

        private static IOrderLine ConvertCmsObject2OrderLine(ICmsObject obj)
        {
            IOrderLine orderLine = new OrderLine();
            orderLine.FromCmsObject(obj);
            return orderLine;
        }
    }
}
